package com.ruoyi.qualityControl.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.qualityControl.domain.*;
import com.ruoyi.qualityControl.domain.vo.QcInfoIndexExamineInTimeEnum;
import com.ruoyi.qualityControl.domain.vo.QcInfoIndexExamineVo;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.qualityControl.mapper.*;
import com.ruoyi.qualityControl.service.QcInfoIndexExamineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class QcInfoIndexExamineServiceImpl implements QcInfoIndexExamineService {
    @Autowired
    private QcInfoIndexExamineCollectMapper qcInfoIndexExamineCollectMapper;
    @Autowired
    private QcInfoIndexExamineInTimeMapper qcInfoIndexExamineInTimeMapper;
    @Autowired
    private QcInfoIndexExamineIntegrityCollectMapper qcInfoIndexExamineIntegrityCollectMapper;
    @Autowired
    private QcInfoIndexExamineIntegrityMapper qcInfoIndexExamineIntegrityMapper;
    @Autowired
    private QcInfoIndexExamineAccuracyMapper qcInfoIndexExamineAccuracyMapper;
    @Autowired
    private QcInfoIndexExamineAccuracyCollectMapper qcInfoIndexExamineAccuracyCollectMapper;

    @Override
    public List<QcInfoIndexExamineInTime> collectInTime(QcInfoIndexExamineVo vo) {
        PageHelper.startPage(vo.getPageDate());
        List<QcInfoIndexExamineInTime> sheets =  qcInfoIndexExamineInTimeMapper.collectInTime(vo);
        for (QcInfoIndexExamineInTime sheet : sheets){
            sheet.setDeliveryLateRate(sheet.getDeliveryLateRate() + "%");
            sheet.setReceiveLateRate(sheet.getReceiveLateRate() + "%");
            sheet.setSignLateRate(sheet.getSignLateRate() + "%");
            sheet.setUploadLateTotalRate(sheet.getUploadLateTotalRate() + "%");
        }
        return sheets;
    }

    @Override
    public List<QcInfoIndexExamineCard> collectOne(QcInfoIndexExamineVo vo) {
        List<QcInfoIndexExamineCard> cards = new ArrayList<>();
        QcInfoIndexExamineCollect collect = qcInfoIndexExamineCollectMapper.collectOne(vo);
//        QcInfoIndexExamineCard card = new QcInfoIndexExamineCard("揽收上传不及时", collect.getTicketOne(), collect.getRateOne(), null, null, null, null);
        cards.add(new QcInfoIndexExamineCard("揽收上传不及时",collect.getTicketOne(),collect.getRateOne(),null,null,null,null));
        cards.add(new QcInfoIndexExamineCard("派件上传不及时",collect.getTicketTwo(),collect.getRateTwo(),null,null,null,null));
        cards.add(new QcInfoIndexExamineCard("签收上传不及时",collect.getTicketThree(),collect.getRateThree(),null,null,null,null));
        return cards;
    }

    @Override
    public List<QcInfoIndexExamineIntegrity> collectIntegrity(QcInfoIndexExamineVo vo) {
        PageHelper.startPage(vo.getPageDate());
        List<QcInfoIndexExamineIntegrity> sheets = qcInfoIndexExamineIntegrityMapper.collectIntegrity(vo);
        for (QcInfoIndexExamineIntegrity sheet : sheets){
            sheet.setDeliveryMissRate(sheet.getDeliveryMissRate() + "%");
            sheet.setReceiveMissRate(sheet.getReceiveMissRate() + "%");
        }
        return sheets;
    }

    @Override
    public List<QcInfoIndexExamineCard> collectTwo(QcInfoIndexExamineVo vo) {
        List<QcInfoIndexExamineCard> cards = new ArrayList<>();
        QcInfoIndexExamineIntegrityCollect collect =  qcInfoIndexExamineIntegrityCollectMapper.collectTwo(vo);
        cards.add(new QcInfoIndexExamineCard("未揽收",collect.getTicketOne(),collect.getRateOne(),null,null,null,null));
        cards.add(new QcInfoIndexExamineCard("未派件",collect.getTicketTwo(),collect.getRateTwo(),null,null,null,null));
        cards.add(new QcInfoIndexExamineCard("未到件",collect.getTicketThree(),collect.getRateThree(),null,null,null,null));
        return cards;
    }

    @Override
    public List<QcInfoIndexExamineAccuracy> collectAccuracy(QcInfoIndexExamineVo vo) {
        PageHelper.startPage(vo.getPageDate());
        List<QcInfoIndexExamineAccuracy> sheets = qcInfoIndexExamineAccuracyMapper.collectAccuracy(vo);
        for (QcInfoIndexExamineAccuracy sheet : sheets){
            sheet.setNoAccuracyRate(sheet.getNoAccuracyRate() + "%");
        }
        return sheets;
    }

    @Override
    public List<QcInfoIndexExamineCard> collectThree(QcInfoIndexExamineVo vo) {
        List<QcInfoIndexExamineCard> cards = new ArrayList<>();
        QcInfoIndexExamineAccuracyCollect collect = qcInfoIndexExamineAccuracyCollectMapper.collectThree(vo);
        cards.add(new QcInfoIndexExamineCard("揽收晚于派件",collect.getTicketOne(),null,"揽收签不准确率",collect.getRateOne(),null,null));
        cards.add(new QcInfoIndexExamineCard("揽收晚于签收",collect.getTicketTwo(),null,null,null,null,null));
        cards.add(new QcInfoIndexExamineCard("派件晚于签收",collect.getTicketThree(),null,null,null,null,null));
        cards.add(new QcInfoIndexExamineCard("派件晚于签收",collect.getTickerFour(),null,null,null,"到件不准确率",collect.getRateTwo()));
        return cards;
    }

    @Override
    public List<TableVo> initTable() {
        List<TableVo> list = new ArrayList<>();
        TableVo tableVo = new TableVo();
        String[] fields = {"collectDate", "contractArea", "networkName", "receiveTotalAmount", "receiveLateAmount", "receiveLateRate"
                , "deliveryTotalAmount", "deliveryLateAmount", "deliveryLateRate", "signTotalAmount", "signLateAmount", "signLateRate"
                , "scanTotalAmount", "uploadLateTotalAmount", "uploadLateTotalRate"};
        for (String field : fields) {
            tableVo = new TableVo();
            tableVo.setFields(field);
            list.add(tableVo);
        }
        for (TableVo vo : list) {
            vo.setTranslate(QcInfoIndexExamineInTimeEnum.getValue(vo.getFields()));
        }
        return list;
    }
}
